package com.bdqn.petmalldemo.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.bdqn.petmalldemo.common.ReturnResult;
import com.bdqn.petmalldemo.entity.Pay;
import com.bdqn.petmalldemo.service.PayService;
import com.bdqn.petmalldemo.utils.CommonUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author Lenovo
 * @since 2020-02-10
 */
@RestController
@RequestMapping("/pay")
@Api(tags = "支付控制器")
public class PayController {

    @Resource
    private PayService payService;

    @ApiOperation(value = "发起支付")
    @PostMapping(value = "add")
    public ReturnResult addPay(String token,String orderId){
        ReturnResult returnResult = CommonUtils.checkUserLogin(token);
        String imageUrl = payService.addPay(orderId);
        return returnResult.data(imageUrl);

    }

    @ApiOperation(value = "查询当前订单的付款记录")
    @PostMapping(value = "list")
    public ReturnResult getPayList(String token,String orderId){
        ReturnResult returnResult = CommonUtils.checkUserLogin(token);
        QueryWrapper<Pay> payQueryWrapper = new QueryWrapper<>();
        payQueryWrapper.eq("order_id",orderId);
        List<Pay> list = payService.list(payQueryWrapper);
        return returnResult.data(list);
    }
}

